﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Input;

namespace InkRun
{
    public class ScrollingLevel : GameObject
    {

        public static Texture2D ScrollingLevelSprite { get; set; }
        public float scale;
        public bool touchingOtherScrollingLevel;
        public enum ScrollingLevelState
        {
            ScrollingRightToLeft,
            Stopped,
            OffScreen
        }

        /// <summary>
        /// The unique ID of the ScrollingLevel
        /// </summary>
        public int ScrollingLevelID { get; set; }

        public ScrollingLevelState scrollingLevelState;

        new public Vector2 velocity;
        public Texture2D sprite;


        public float timeTillNextShot;

        public int upKey, downKey, leftKey, rightKey, fireKey;
        public Color color;


        public int Lives { get; set; }
        public bool NoLivesLeft { get; set; }

        public ScrollingLevel(Vector2 position, Texture2D sprite)
            : base(position)
        {
            this.sprite = sprite;
            scale = 1.0f;
            sizeInPixels = new Vector2(scale * this.sprite.Bounds.Width, scale * this.sprite.Bounds.Height);
            scrollingLevelState = ScrollingLevelState.Stopped;
            velocity = new Vector2(-2.0f, 0.0f);
            SetUpScrollingLevel();
        }

        public void SetUpScrollingLevel()
        {
        }

        public void ResetScrollingLevel()
        {

        }

        public override void Update(GameTime gameTime)
        {

            float elapsedTime = (float)gameTime.ElapsedGameTime.TotalSeconds;

            switch (scrollingLevelState)
            {
                case ScrollingLevelState.ScrollingRightToLeft:
                    position.X += velocity.X;
                    if (IsOffLeftSideOfScreen())
                    {
                        scrollingLevelState = ScrollingLevelState.OffScreen;
                    }
                    break;
                case ScrollingLevelState.Stopped:

                    break;
                case ScrollingLevelState.OffScreen:
                    Die();
                    break;
                default:
                    break;
            }
        }

        public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            switch (scrollingLevelState)
            {
                case ScrollingLevelState.ScrollingRightToLeft:
                    spriteBatch.Draw(sprite, position, null, Color.White, 0, new Vector2(sprite.Bounds.Center.X, sprite.Bounds.Center.Y), scale, SpriteEffects.None, 0);

                    break;
                case ScrollingLevelState.Stopped:
                    spriteBatch.Draw(sprite, position, null, Color.White, 0, new Vector2(sprite.Bounds.Center.X, sprite.Bounds.Center.Y), scale, SpriteEffects.None, 0);

                    break;
                case ScrollingLevelState.OffScreen:
                    break;
                default:
                    break;
            }
        }

        public override void Die()
        {
            base.Die();
        }
    }
}
